package com.spboot.exts.service.impl;

import com.spboot.exts.entity.Role;
import com.spboot.exts.mapper.RoleMapper;
import com.spboot.exts.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author test
 * @since 2019-08-31
 */
@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

	public boolean addRoleAndPerm(Role role, Long[] permIds) {
		int f = this.baseMapper.insert(role);
		if (f > 0) {
			// 保存权限
			return this.baseMapper.addRolePermission(role.getId(), permIds) > 0;
		}
		return false;
	}

	public boolean updateRolePerm(Long id, Long[] permId) {
		//删除角色权限
		this.baseMapper.delRolePermission(id);
		return this.baseMapper.addRolePermission(id, permId) > 0;
	}
}
